import 'dart:math';

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

String generateRandomString(int length) {
  const letters = 'abcdefghijklmnopqrstuvwxyz';
  final random = Random();
  final codeUnits = List.generate(length, (index) {
    final randomIndex = random.nextInt(letters.length);
    return letters.codeUnitAt(randomIndex);
  });
  return String.fromCharCodes(codeUnits);
}

void showToast(String msg) {
  Fluttertoast.showToast(
      msg: msg,
      backgroundColor: Colors.black45,
      fontSize: 14
  );
}

Future showSlideDialog(BuildContext context, Dialog dialog, {bool barrierDismissible = true}) async {
  await showGeneralDialog(
      context: context,
      barrierColor: Colors.black.withOpacity(0.4),
      barrierDismissible: barrierDismissible,
      barrierLabel: "",
      transitionDuration: const Duration(milliseconds: 200),
      transitionBuilder: (BuildContext context, Animation<double> anim1, Animation<double> anim2, child) {

        return SlideTransition(
          position: anim1.drive(Tween(begin: const Offset(0, 1), end: Offset.zero)),
          child: child,
        );

      },
      pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
        return dialog;
      }
  );
}